package cn.zjitc.service.impl;

import cn.zjitc.dao.UserDao;
import cn.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

//    <bean id="userService" class="cn.zjitc.service.impl.UserServiceImpl">
//@Component("userService")
@Service("userService")
@Scope("prototype")
public class UserServiceImpl implements UserService {

//    @Value("zjitc") // zjitc
    @Value("${jdbc.driver}") // com.mysql.cj.jdbc.Driver
    private String driver;

    //<property name="userDao" ref="userDao"></property>
    // @Autowired // 按照数据类型从spring容器进行匹配
    // @Qualifier("userDao") // 是按照id值从容器中进行匹配的，但是主要此处@Qualifier结合@Autowired一起使用
    @Resource(name = "userDao") // @Resource相当于@Qualifier+@Autowired
    private UserDao userDao;

    /*public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    @Override
    public void save() {
        System.out.println(driver);
        userDao.save();
    }

    @PostConstruct
    public void init(){
        System.out.println("service对象的初始化方法");
    }

    @PreDestroy
    public void destory(){
        System.out.println("service对象的销毁方法");
    }
}
